package Demo05.Demo06;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

public class BefferTest {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入要写的信息");
        String inputContents = scan.next();
        BufferedOutputStream out =null;
        try {
             out = new BufferedOutputStream(new FileOutputStream("2.txt"));
             byte[] data=inputContents.getBytes();
             //data=inputContents.getBytes(StandardCharsets.UTF_8);
            out.write(data,0,data.length);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                out.flush();
               if(out!=null) out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

